import Vue from 'vue';
import VueRouter from 'vue-router';
import Login from '@/views/login';
import ErrorPage from '@/views/404.vue';

Vue.use(VueRouter);

export const publicRoutes = [
  {
    path: '/login',
    name: 'login',
    component: Login,
  },
  {
    path: '/404',
    name: '404',
    component: ErrorPage,
  }
];



export const promiseRoutes = () => ([
  {
    path: '/',
    name: 'layout',
    component: () => import('@/views/layout'),
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'home',
        component: () => import('@/views/home'),
      },
      {
        path: '/role/subRole1',
        name: 'role1',
        component: () => import('@/views/role/subRole1'),
      },
      {
        path: '/role/subRole2',
        name: 'role2',
        component: () => import('@/views/role/subRole2'),
      },
      {
        path: '/gaodeMap',
        name: 'gaodeMap',
        component: () => import('@/views/gaodeMap'),
      },
      {
        path: '/role/subRole4',
        name: 'role4',
        component: () => import('@/views/role/subRole2'),
      },
    ]
  },
  {
    path: '*',
    name: 'error',
    redirect: '/404',
  }
])


const router = new VueRouter({
  mode: 'history',
  routes: publicRoutes,
});



const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}


export default router;
